﻿namespace YK.Console.Business.DataDictItems;

internal class CreateDataDictItemValidator : AbstractValidator<CreateDataDictItemRequest>
{
    public CreateDataDictItemValidator(IReadRepository<DataDictItemInfo> _repo)
    {
        RuleFor(x => x.Value)
            .MustAsync(async (value, ct) => !await _repo.SimpleAnyAsync(x => x.Value == value, ct))
            .WithMessage((_,value) => $" 字典值 {value} 重复 ");
    }
}


internal class UpdateDataDictItemValidator : AbstractValidator<UpdateDataDictItemRequest>
{
    public UpdateDataDictItemValidator(IReadRepository<DataDictItemInfo> _repo)
    {
        RuleFor(x => x.Value)
            .MustAsync(async (inst, value, ct) => !await _repo.SimpleAnyAsync(x => x.Value == value && x.Id != inst.Id, ct))
            .WithMessage((_, value) => $" 字典值 {value} 重复");
    }
}
